package com.pe.pgn.clubpgn.dao.impl;

import java.util.Iterator;
import java.util.List;

import javax.sql.DataSource;

import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pe.pgn.clubpgn.dao.TestDao;
import com.pe.pgn.clubpgn.dao.hibernate.GenericDaoHibernate;
import com.pe.pgn.clubpgn.domain.Detalle;
import com.pe.pgn.clubpgn.domain.Maestro;

@Repository
public class TestDaoImpl extends GenericDaoHibernate<Maestro, Long> implements TestDao {

	public TestDaoImpl(){
		super(Maestro.class);
	}

	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public void guardarMaestro(Maestro maestro, List<Detalle> detalles) {
				
		try {
			
			getHibernateTemplate().saveOrUpdate(maestro);
			
			for(Iterator<Detalle> iter = detalles.iterator(); iter.hasNext(); ){
				
				Detalle detalle = iter.next();
				detalle.setMaestro(maestro);	
			}
			
			jdbcTemplate.update(" update detalle set nombre = 'michelu =P' where id = 29124 ");
									
			getHibernateTemplate().saveOrUpdateAll(detalles);

			getHibernateTemplate().flush();
			
		} catch (Exception e) {
			log.info(e.getMessage());
			System.out.println(e.getMessage());
		}
		
	}

	
	public Maestro obtenerMaestro(Long id) {
		
		return null;
	}

	
	public List<Maestro> obtenerMaestros() {
		
		return null;
	}

}
